package com.istart.boilerpipe;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.List;

import de.l3s.boilerpipe.BoilerpipeExtractor;
import de.l3s.boilerpipe.BoilerpipeProcessingException;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.extractors.CommonExtractors;
import de.l3s.boilerpipe.sax.ImageExtractor;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws BoilerpipeProcessingException, MalformedURLException
    {
    	 URL url = new URL("http://segmentfault.com/a/1190000000349384");
    	   // NOTE: Use ArticleExtractor unless DefaultExtractor gives better results for you
    	   String text = ArticleExtractor.INSTANCE.getText(url);
    	   System.out.println(text);
    }
    
    public void findLargestImage(String url) {
        final BoilerpipeExtractor extractor = CommonExtractors.ARTICLE_EXTRACTOR;
        final ImageExtractor ie = ImageExtractor.INSTANCE;

        List imgUrls = ie.process(url, extractor);
                    
        // automatically sorts them by decreasing area, i.e. most probable true positives come first
        Collections.sort(imgUrls);
        if (!imgUrls.isEmpty()) {
            System.out.println("* "+imgUrls.get(0));
        }
    }
}
